What is is-array-buffer?
The is-array-buffer npm package is a simple utility that allows you to check if a given value is an ArrayBuffer. It is useful when dealing with binary data in JavaScript, as it helps ensure that the data being processed is in the expected format.
What are is-array-buffer's main functionalities?
Check if a value is an ArrayBuffer
This feature allows you to verify whether a given value is an instance of ArrayBuffer. It is particularly useful when working with APIs that expect binary data and you need to validate the input.
const isArrayBuffer = require('is-array-buffer');
const buffer = new ArrayBuffer(8);
const result = isArrayBuffer(buffer); // result will be true
Other packages similar to is-array-buffer
is-typedarray
The is-typedarray package is similar to is-array-buffer in that it checks if a value is a TypedArray, which is closely related to ArrayBuffer. It differs in that it specifically checks for TypedArray instances rather than ArrayBuffers.
buffer
The buffer package includes a method called Buffer.isBuffer which checks if an object is a Node.js Buffer, which is a way to handle binary data in Node.js. This is similar to is-array-buffer but is specific to Node.js Buffers rather than ArrayBuffers.
is-buffer
Similar to the buffer package, is-buffer provides a function to check if an object is a Buffer. It is designed to work in both Node.js and browser environments, making it a bit more versatile than the buffer package's Buffer.isBuffer method.
is-array-buffer
Is this value a JS ArrayBuffer? This module works cross-realm/iframe, does not depend on instanceof
or mutable properties, and despite ES6 Symbol.toStringTag.
Example
var assert = require('assert');
var isArrayBuffer = require('is-array-buffer');
assert(!isArrayBuffer(function () {}));
assert(!isArrayBuffer(null));
assert(!isArrayBuffer(function* () { yield 42; return Infinity; });
assert(!isArrayBuffer(Symbol('foo')));
assert(!isArrayBuffer(1n));
assert(!isArrayBuffer(Object(1n)));
assert(!isArrayBuffer(new Set()));
assert(!isArrayBuffer(new WeakSet()));
assert(!isArrayBuffer(new Map()));
assert(!isArrayBuffer(new WeakMap()));
assert(!isArrayBuffer(new WeakRef({})));
assert(!isArrayBuffer(new FinalizationRegistry(() => {})));
assert(!isArrayBuffer(new SharedArrayBuffer()));
assert(isArrayBuffer(new ArrayBuffer()));
class MyArrayBuffer extends ArrayBuffer {}
assert(isArrayBuffer(new MyArrayBuffer()));
Tests
Simply clone the repo, npm install
, and run npm test